package com.inight.nightojbackendquestionservice.controller.inner;


import com.inight.nightojbackendquestionservice.service.QuestionService;
import com.inight.nightojbackendquestionservice.service.QuestionSubmitService;
import com.inight.nightojbackendserviceclient.service.QuestionFeignClient;
import nightojbackendmodel.entity.Question;
import nightojbackendmodel.entity.QuestionSubmit;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 该服务仅是内部服务调用, 不暴露给前端
 */
@RestController
@RequestMapping("/inner")
public class QuestionInnerController implements QuestionFeignClient {

    // 调用用户的 service
    @Resource
    private QuestionService questionService;

    @Resource
    private QuestionSubmitService questionSubmitService;

    /**
     * 根据题目id 获取题目
     * @param questionId
     * @return
     */
    @Override
    @GetMapping("/get/id")
    public Question getQuestionById(@RequestParam("questionId") long questionId){
        return questionService.getById(questionId);
    }


    /**
     *  根据id 获取用户提交信息
     * @param questionSubmitId
     * @return
     */
    @Override
    @GetMapping("/question_submit/get/id")
    public QuestionSubmit getQuestionSubmitById(@RequestParam("questionSubmitId") long questionSubmitId) {
        return questionSubmitService.getById(questionSubmitId);
    }


    /**
     * 更新修改
     * @param questionSubmit
     * @return
     */
    @Override
    @PostMapping("/question_submit/update")
    public boolean updateQuestionSubmitById(@RequestBody QuestionSubmit questionSubmit) {
        return questionSubmitService.updateById(questionSubmit);
    }



}
